package com.itcam.beanutil;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

/**
 * @author : Cammy.Wu
 * Description : 
 */

@Slf4j
public class BeanUtilTest {

    public static void main(String[] args) {
        UserPO userPO = new UserPO();
        userPO.setUserId(1L);
        userPO.setUserName("John");
        userPO.setPassword("password");
        userPO.setCreateTime(new Date());
        userPO.setAge(25);
        userPO.setAddress(new AddressPO("Peking", "Main street"));

        UserDTO userDTO = new UserDTO();
//        BeanUtil.copyProperties(userPO, userDTO, CopyOptions.create()
//                .setIgnoreProperties("password"));  // 忽略敏感字段
        BeanUtil.copyProperties(userPO, userDTO);

        System.out.println("userDTO = " + userDTO);
    }

    @Data
    public static class UserPO {
        private Long userId;
        private String userName;
        private String password;
        private Date createTime;
        private Integer age;
        private AddressPO address; // 嵌套对象
    }

    @Data
    @AllArgsConstructor
    public static class AddressPO {
        private String city;
        private String street;
    }

    @Data
    public static class UserDTO {
        private Long userId;
        private String userName;
        private Date createTime;
        private Integer age;
        private AddressDTO address;
    }

    @Data
    public static class AddressDTO {
        private String city;
        private String street;
    }

    @Data
    public static class UserVO {
        private Long id;
        private String displayName;
        private String createTimeStr; // 日期格式化
        private String fullAddress;   // 嵌套字段合并
    }
}
